using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public static GameManager Instance { get; private set; }
    public GameObject CurrentMonster { get; set; }

    public GameObject candles;
    public bool CandlesVisible { get; set; } = true;

    public bool QuestLoaded { get; set; } = false;

    private AudioSource audioSource;
    private AudioClip musicNormal;
    private AudioClip musicBattle;
    private AudioClip audioCompleteQuest;
    private AudioClip audioFootStep;

    void Awake()
    {
        Instance = this;
        this.audioSource = GetComponent<AudioSource>();
        this.musicNormal = Resources.Load<AudioClip>("Audios/Scene/Normal");
        this.musicBattle = Resources.Load<AudioClip>("Audios/Scene/Battle");
        this.audioCompleteQuest = Resources.Load<AudioClip>("Audios/Luna/Complete");
    }

    void Start()
    {
        StartCoroutine(nameof(InitCoroutine));
        PlayNormalMusic();
    }

    IEnumerator InitCoroutine()
    {
        while (!this.QuestLoaded)
        {
            yield return null;
        }
        // 任务重新加载后需根据任务进度设置蜡烛状态
        this.candles.SetActive(this.CandlesVisible);
    }

    public void PlaySound(AudioClip audioClip)
    {
        if(audioClip)
        {
            audioSource.PlayOneShot(audioClip);
        }
    }

    public void PlayMusic(AudioClip audioClip)
    {
        if (this.audioSource.clip != audioClip)
        {
            this.audioSource.clip = audioClip;
            this.audioSource.Play();
        }
    }

    public void StopAudio()
    {
        this.audioSource.Stop();
    }

    public void PlayNormalMusic()
    {
        this.PlayMusic(this.musicNormal);
    }

    public void PlayBattleMusic()
    {
        this.PlayMusic(this.musicBattle);
    }

    public void PlaySoundCompleteQuest()
    {
        this.PlaySound(this.audioCompleteQuest);
    }
    
    public void PlaySoundFootStep()
    {
        this.PlaySound(this.audioFootStep);
    }
}
